﻿using System;
using System.IO;
using System.Windows;
using Telerik.Windows.Controls;

namespace LeoK.Common
{ 
    /// <summary>
    /// 日志登记类
    /// </summary>
    public class LogHelper
    {
        public static void LogError(Exception ex)
        {
            using (StreamWriter sw = new StreamWriter("Log.txt", true))
            {
                sw.WriteLine("---------------------------------------------------------------------------");
                sw.WriteLine("Time：" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                sw.WriteLine("Message："+ex.Message);
                if (ex.InnerException != null)
                {
                    sw.WriteLine("Inner Message：" + ex.InnerException.Message);
                }
                sw.WriteLine("Track：");
                sw.Write(ex.StackTrace);
                sw.WriteLine();
            }

            Application.Current.Dispatcher.BeginInvoke(new Action(() => RadWindow.Alert("发生错误：" + ex.Message)));
        }
    }
}
